#pragma once

#include <Tlhelp32.h>
#include <Psapi.h>

class CProcess
{
private:
	CProcess(PROCESSENTRY32 pe32);

public:
	~CProcess(void);
	
private:
	static HANDLE hProcessSnap;
	static PROCESSENTRY32 pe32;
	static TCHAR szProcessFind[MAX_PATH];
	static DWORD pidFind;

public:
	TCHAR szProcessName[256];
	TCHAR szExePath[MAX_PATH];
	HANDLE hProcess;
	DWORD dwBaseAddress;
	DWORD dwCodeAddress;
	DWORD dwDataAddress;
	DWORD dwProcessId;	
	
public:
	static CProcess* FindProcess(DWORD pid);
	static CProcess* FindProcess(TCHAR* szProcessName);
	static CProcess* FindProcess(DWORD pid, TCHAR* szProcessName);
	static CProcess* FindProcessNext();

public:
	void EnableDebugPrivilege(HANDLE hProcess);
	PROCESSENTRY32 GetProcessEntry();
	MODULEENTRY32 GetModuleInfo(TCHAR* szModuleName);
	THREADENTRY32 GetMainThread();
	HANDLE GetHandle( const DWORD dwProcessId_i );
	BOOL Write(LPCWSTR szFile);
	BOOL Write(DWORD_PTR dwOffset, BYTE* buffer, int nByte);	
	BOOL Read(DWORD_PTR dwOffset, BYTE* buffer, int nByte);	
	BOOL Verify(LPCWSTR szFile) ;	// Check whether the running code of the process match with content of the file
	BOOL Verify(DWORD dwOffset, BYTE* bTest, int nByte);
	BOOL Terminate(int nExitCode);
	BOOL Find(DWORD* dwOffset, BYTE* bPattern, int nBytes);	
	BOOL Find(DWORD* dwOffset, DWORD dwTo, BYTE* bPattern, int nBytes);
};
